/*
 * UserIdWrapper.java
 *
 * Created on July 22, 2007, 10:45 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package listeners;

import java.sql.SQLException;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionBindingEvent;
import javax.servlet.http.HttpSessionBindingListener;
import model.Salesman;

/**
 *
 * @author Alirio
 */
public class UserIdWrapper implements HttpSessionBindingListener {
    
    private String userId = "default";
    
    /** Creates a new instance of UserIdWrapper */
    public UserIdWrapper(String id) {
        this.userId = id;
    }
    
    public void valueBound(HttpSessionBindingEvent event) {
    }
    
    public void valueUnbound(HttpSessionBindingEvent event) {
        HttpSession session = event.getSession();
                
        //actualizamos el status de logged
        java.sql.Connection cnn = (java.sql.Connection) session.getServletContext().getAttribute("cnn");
        try {
            java.sql.Statement stmt2 = cnn.createStatement();
            stmt2.executeUpdate("update salesmen set logged=0 where salesman_id='" + this.userId + "'");
            stmt2.close();
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
    }
    
}
